<?php

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;
use App\Models\Floor;
use App\Models\Household;
use Illuminate\Http\Request;

class FloorController extends Controller
{
    /*
     * 楼面列表 显示  栋数
     * */
    public function index(Request $Request, Household $household, Floor $floor)
    {
        $res = $floor->wherecommunity_id($Request->community_id)->get()->toArray();
        $data['dong'] = $this->searchmax($res, 'number');
        $data['dan'] =  $this->searchmax($res, 'unit');
        return $this->return_json(200, $data, '列表信息');
    }


    public function save()
    {


    }

    public function update()
    {


    }

    public function delete()
    {


    }


    /*
     *列表显示
     * */
    public function lists(Request $request, Household $household)
    {
        $this->validate($request,
            ['foller' => 'required', 'unit' => 'required'],
            ['foller.required' => '栋数不能为空', 'unit.required' => '单元不能为空']);
        $res = $household->wherefloor_don($request->foller)->whereunit($request->unit)->get()->toArray();
        if ($res) {
            return $this->return_json(200, $res, '单元信息');
        } else {
            return $this->return_json(201, $res, '单元信息查找失败');
        }
    }
}